package com.doyoo.service.impl;

import io.kubernetes.client.openapi.ApiException;
import io.kubernetes.client.openapi.apis.BatchV1Api;
import io.kubernetes.client.openapi.apis.BatchV1beta1Api;
import io.kubernetes.client.openapi.models.V1Job;
import io.kubernetes.client.openapi.models.V1JobSpec;
import io.kubernetes.client.openapi.models.V1JobStatus;
import io.kubernetes.client.openapi.models.V1ObjectMeta;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class BatchV1ApiService {
    @Resource
    private BatchV1Api batchV1Api;
    @Resource
    private BatchV1beta1Api batchV1beta1Api;

    public void createNamespacedJob(String namespace) throws ApiException {
        V1Job v1Job = new V1Job();
        v1Job.setApiVersion("batch/v1beta1");
        v1Job.setKind("Job");
        v1Job.setMetadata(new V1ObjectMeta());
        v1Job.setSpec(new V1JobSpec());
        v1Job.setStatus(new V1JobStatus());
        batchV1Api.createNamespacedJob(namespace, v1Job, null, null, null);
    }
}
